//
// Created by 吴锐 on 2022/2/26.
//

#include "iostream"

using namespace std;

class CPU {
public:
    virtual void calculate() = 0;
};

class VideoCard {
public:
    virtual void display() = 0;
};

class Memory {
public:
    virtual void storage() = 0;
};

class Computer {
private:
    CPU *cpu;
    VideoCard *videoCard;
    Memory *memory;

public:
    Computer(CPU *cpu, VideoCard *videoCard, Memory *memory) {
        this->cpu = cpu;
        this->videoCard = videoCard;
        this->memory = memory;
    }

    void work() {
        this->cpu->calculate();
        this->videoCard->display();
        this->memory->storage();
    }

    ~Computer() {
        if (this->cpu != NULL) {
            delete this->cpu;
        }
        if (this->videoCard != NULL) {
            delete this->videoCard;
        }
        if (this->memory != NULL) {
            delete this->memory;
        }
    }
};

class LenovoCPU : public CPU {
public:
    virtual void calculate() {
        cout << "Lenovo的CPU开始计算了" << endl;
    }
};

class LenovoVideoCard : public VideoCard {
public:
    virtual void display() {
        cout << "Lenovo的显卡开始工作了" << endl;
    }
};

class LenovoMemory : public Memory {
public:
    virtual void storage() {
        cout << "Lenovo内存条开始工作了" << endl;
    }
};

class IntelCPU : public CPU {
public:
    virtual void calculate() {
        cout << "Intel的CPU开始计算了" << endl;
    }
};

class IntelVideoCard : public VideoCard {
public:
    virtual void display() {
        cout << "intel的显卡开始工作了" << endl;
    }
};

class IntelMemory : public Memory {
public:
    virtual void storage() {
        cout << "intel内存条开始工作了" << endl;
    }
};

void test01() {
    CPU* intelCPU = new IntelCPU;
    VideoCard* intelCard = new IntelVideoCard;
    Memory* intelMemory = new IntelMemory;

    Computer* computer1 = new Computer(intelCPU, intelCard, intelMemory);
    computer1->work();
    delete computer1;
    cout << "-----------------------" << endl;
    CPU *lenovoCPU = new LenovoCPU;
    VideoCard *lenovoCard = new LenovoVideoCard;
    Memory *lenovoMemory = new LenovoMemory;

    Computer* computer2 = new Computer(lenovoCPU, lenovoCard, lenovoMemory);
    computer2->work();
    delete computer2;
}

int main() {
    test01();
    return 0;
}